<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组解构</title>
</head>

<body>
    <script>
        let numbers = ['one', 'two', 'three', 'four'];

        //let [one, two] = number
        //获取下标0-3位置的元素
        //let [one, ,three] = numbers
        //使用one以后的所以数组元素
        let [one, ...others] = numbers

        console.log(one, others)

        //应用场景:交换变量值
        //传统写法
        /*
        let a = 10;
        let b = 20;
        let temp;
        temp = a
        a = b
        b = temp
        console.log(a, b)
        */
        //新写法
        let a = 10;
        let b = 20;

        [a, b] = [b, a]
        console.log(a, b)
    </script>
</body>

</html>